package efr.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import efr.dao.AutorDao;
import efr.dao.impl.AutorDaoImpl;
import efr.entity.Autor;
import efr.util.SendMailTLS;

/**
 * Servlet implementation class ListAutoriServlet
 */
public class ListAutoriServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(ListAutoriServlet.class);
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListAutoriServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("start doGet()");
		logger.debug("before send mail");
		logger.debug(getClass().getResource("/javax/mail/Address.class"));
//		SendMailTLS.sendMail();
		logger.debug("after send mail");
		request.setCharacterEncoding("UTF-8");
		AutorDao autorDao = new AutorDaoImpl();
		List<Autor> listAutors = autorDao.getAllAutori();
		request.setAttribute("listAutors", listAutors);
		RequestDispatcher view = request.getRequestDispatcher("/indexAutor.jsp");
		logger.debug("end doGet()");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
